
#include "clientStdafx.h"
#include "ClientRoot.h"
#include "RegisterGUI.h"

using namespace Apo;

//---------------------------------------------------------------------------------------------
OGUIWidget::OGUIWidget() : 
m_Handle(0), m_Parent(0), m_Type(WIDGET_NONE), m_Caption(""), m_ID(-1), m_SystemID(-1), m_Enabled(false), m_Checked(false)
{
    m_SystemID = ClientRoot::getInstance().GetNextControlID(this);
    m_Children.clear();
}
//---------------------------------------------------------------------------------------------
OGUIWidget::~OGUIWidget()
{
    Clear();
	
    ClientRoot::getInstance().TerminateGUIControl(this);
}
//---------------------------------------------------------------------------------------------
void OGUIWidget::AddChild(OGUIWidget *widget)
{
    widget->SetParent(this);
    m_Children.push_back(widget);
}
//---------------------------------------------------------------------------------------------
void OGUIWidget::Clear(bool deletechildren)
{
    if(deletechildren)
    {
        for(unsigned int i = 0;i < m_Children.size();i++)
        {
            delete m_Children[i];
        }
    }
    m_Children.clear();
}
//---------------------------------------------------------------------------------------------
OGUIWidget *OGUIWidget::FindChildBySystemID(int ID)
{
    for(unsigned int i = 0;i < m_Children.size();i++)
    {
        if(m_Children[i]->m_SystemID == ID)
            return m_Children[i];
    }
    return 0;
}
//---------------------------------------------------------------------------------------------
OGUIWidget *OGUIWidget::FindChildByID(int ID)
{
    for(unsigned int i = 0;i < m_Children.size();i++)
    {
        if(m_Children[i]->m_ID == ID)
            return m_Children[i];
    }
    return 0;
}
//---------------------------------------------------------------------------------------------
void OGUIWidget::OnCommand(CommandEvent& event)
{
   if(m_Parent)
       m_Parent->OnCommand(event);
}
//---------------------------------------------------------------------------------------------
void OGUIWidget::OnUpdate(UpdateEvent& event)
{
   if(m_Parent)
       m_Parent->OnUpdate(event);
}
//---------------------------------------------------------------------------------------------
OGUIButton::OGUIButton(int ID, String Caption, String bmp16, String bmp32) : 
m_Bitmap16(bmp16), m_Bitmap32(bmp32)
{
    m_Type = WIDGET_BUTTON;
    m_Enabled = true;
    m_Caption = Caption;
    m_ID = ID;
}
//---------------------------------------------------------------------------------------------
String OGUIButton::GetBitmap(int size)
{
    if(size == 16)
        return m_Bitmap16;
    else if(size == 32)
        return m_Bitmap32;
    else
        return "";
}
//---------------------------------------------------------------------------------------------
void OGUIButton::SetMenu(OGUIMenu *newmenu, bool deleteold)
{
    Clear(deleteold);
    AddChild(newmenu);
}
//---------------------------------------------------------------------------------------------
OGUICombo::OGUICombo(int ID, int width, stringvector items):
m_Width(width), m_Items(items), m_ItemIndex(-1)
{
    m_Type = WIDGET_COMBO;
    m_Enabled = true;
    m_ID = ID;
}
//---------------------------------------------------------------------------------------------
int OGUICombo::GetIndex()
{
    if(m_Handle)
    {
        m_ItemIndex = gSkinSystem->GetGUIControlIndex(this);
    }
    return m_ItemIndex;
}
//---------------------------------------------------------------------------------------------
String OGUICombo::GetText()
{
    if(m_Handle)
    {
        return gSkinSystem->GetGUIControlText(this);
    }
    else
        return "";
}
//---------------------------------------------------------------------------------------------
void OGUICombo::SetIndex(int IDX)
{
    if(m_Handle)
    {
        return gSkinSystem->SetGUIControlIndex(this, IDX);
    }
    else
        m_ItemIndex = IDX;
}
//---------------------------------------------------------------------------------------------
void OGUICombo::SetText(String text)
{
    if(m_Handle)
    {
        return gSkinSystem->SetGUIControlText(this, text);
    }
}
//---------------------------------------------------------------------------------------------
void OGUICombo::SetItems(stringvector items)
{
    m_Items = items;
    if(m_Handle)
    {
        return gSkinSystem->SetGUIControlItems(this, items);
    }
}
//---------------------------------------------------------------------------------------------
OGUIEdit::OGUIEdit(int ID, int width, String Text, bool hideChars):
m_Width(width), m_Text(Text), m_HideChars(hideChars)
{
    m_Type = WIDGET_EDIT;
    m_Enabled = true;
    m_ID = ID;
}
//---------------------------------------------------------------------------------------------
String OGUIEdit::GetText()
{
    if(m_Handle)
    {
        return gSkinSystem->GetGUIControlText(this);
    }
    else
        return m_Text;
}
//---------------------------------------------------------------------------------------------
void OGUIEdit::SetText(String text)
{
    if(m_Handle)
    {
        return gSkinSystem->SetGUIControlText(this, text);
    }
    else
        m_Text = text;
}
//---------------------------------------------------------------------------------------------
OGUIMenu::OGUIMenu(int ID, String Caption, String bmp16) 
{
    m_Type = WIDGET_MENU;
    m_Enabled = true;
    m_ID = ID;
    m_Caption = Caption;
    m_Bitmap16 = bmp16;
}
//---------------------------------------------------------------------------------------------
OGUIMenu::~OGUIMenu()
{
}
//---------------------------------------------------------------------------------------------
OGUIMenu *OGUIMenu::AddItem(int ID, String Caption, String bmp16)
{
    OGUIMenu *widget = new OGUIMenu(ID, Caption, bmp16);
    widget->SetType(WIDGET_MENUITEM);
    m_Type = WIDGET_MENU;
    AddChild(widget);
    return widget;
}
//---------------------------------------------------------------------------------------------
void OGUIMenu::AddSeparator()
{
    OGUIWidget *widget = new OGUIWidget();
    widget->SetType(WIDGET_SEPARATOR);
    AddChild(widget);
}
//---------------------------------------------------------------------------------------------
OGUILabel::OGUILabel(int ID, String Caption) 
{
    m_Type = WIDGET_LABEL;
    m_Enabled = true;
    m_ID = ID;
    m_Caption = Caption;
}
//---------------------------------------------------------------------------------------------
OGUIEvent::OGUIEvent()
{
}
//---------------------------------------------------------------------------------------------
OGUIToolbar::OGUIToolbar(int ID, String Caption)
{
    m_Type = WIDGET_TOOLBAR;
    m_ID = ID;
    m_Caption = Caption;
}
//---------------------------------------------------------------------------------------------
OGUIToolbar::~OGUIToolbar()
{
}
//---------------------------------------------------------------------------------------------
void OGUIToolbar::AddSeparator()
{
    OGUIWidget *widget = new OGUIWidget();
    widget->SetType(WIDGET_SEPARATOR);
    AddChild(widget);
}
//---------------------------------------------------------------------------------------------
OGUILabel *OGUIToolbar::AddLabel(int ID, String Caption)
{
    OGUILabel *widget = new OGUILabel(ID, Caption);
    AddChild(widget);
    return widget;
}
//---------------------------------------------------------------------------------------------
OGUIButton *OGUIToolbar::AddButton(int ID, String Caption, String bmp16, String bmp32)
{
    OGUIButton *widget = new OGUIButton(ID, Caption, bmp16, bmp32);
    AddChild(widget);
    return widget;
}
//---------------------------------------------------------------------------------------------
OGUICombo *OGUIToolbar::AddCombo(int ID, int width, stringvector items)
{
    OGUICombo *widget = new OGUICombo(ID, width, items);
    AddChild(widget);
    return widget;
}
//---------------------------------------------------------------------------------------------
OGUIEdit *OGUIToolbar::AddEditBox(int ID, int width, String Text, bool hideChars)
{
    OGUIEdit *widget = new OGUIEdit(ID, width, Text, hideChars);
    AddChild(widget);
    return widget;
}
//---------------------------------------------------------------------------------------------
OGUIToolbar *OGUIToolbar::AddToolbar(int ID, String Caption)
{
    OGUIToolbar *widget = new OGUIToolbar(ID, Caption);
    widget->SetType(WIDGET_SUBTOOLBAR);
    AddChild(widget);
    return widget;
}
//---------------------------------------------------------------------------------------------
OGUICategoryBar::OGUICategoryBar(int ID, String Caption)
{
    m_Type = WIDGET_CATEGORYBAR;
    m_ID = ID;
    m_Caption = Caption;
}
//---------------------------------------------------------------------------------------------
OGUICategoryBar::~OGUICategoryBar()
{
}
//---------------------------------------------------------------------------------------------
OGUIToolbar *OGUICategoryBar::AddToolbar(int ID, String Caption)
{
    OGUIToolbar *widget = new OGUIToolbar(ID, Caption);
    AddChild(widget);
    return widget;
}
//---------------------------------------------------------------------------------------------

